package o;

import android.net.Uri;
import android.webkit.ValueCallback;
import com.huawei.appgallery.common.media.api.OriginalMediaBean;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import o.bag.c;

public class baf {
    private static baf ॱ;
    private Map<String, a> ˏ = new HashMap();

    static class a {
        private ValueCallback<Uri[]> ˊ;
        private ValueCallback<Uri> ˏ;

        private a() {
        }

        public void ˊ(List<Uri> list) {
            if (this.ˏ != null) {
                this.ˏ.onReceiveValue(list.get(0));
                this.ˏ = null;
            } else if (this.ˊ != null) {
                this.ˊ.onReceiveValue(list.toArray(new Uri[list.size()]));
                this.ˊ = null;
            }
        }

        public void ˏ() {
            if (this.ˏ != null) {
                this.ˏ.onReceiveValue(null);
                this.ˏ = null;
            } else if (this.ˊ != null) {
                this.ˊ.onReceiveValue(null);
                this.ˊ = null;
            }
        }
    }

    private baf() {
    }

    public static synchronized baf ॱ() {
        baf o_baf;
        synchronized (baf.class) {
            if (ॱ == null) {
                ॱ = new baf();
            }
            o_baf = ॱ;
        }
        return o_baf;
    }

    public String ॱ(ValueCallback<Uri[]> valueCallback) {
        String ˎ = ˎ();
        a aVar = new a();
        aVar.ˊ = valueCallback;
        this.ˏ.put(ˎ, aVar);
        aVar.ˏ = null;
        return ˎ;
    }

    private String ˎ() {
        return UUID.randomUUID().toString() + "_" + System.currentTimeMillis();
    }

    public void ˏ(int i, int i2, final String str, List<OriginalMediaBean> list) {
        if (dof.ॱ(str)) {
            azh.ˏ.ˏ("ChooseFileManager", "onActivityResult, error no callbackID");
        } else if (1000 != i || -1 != i2) {
            ˊ(str);
        } else if (list == null || list.size() == 0) {
            ˊ(str);
        } else {
            new bag(list, new c(this) {
                final /* synthetic */ baf ˊ;

                public void ˊ(List<String> list) {
                    this.ˊ.ॱ(str, list);
                }
            }).executeOnExecutor(eps.ˋ, new Object[0]);
        }
    }

    public void ˊ(String str) {
        if (!dof.ॱ(str)) {
            a aVar = (a) this.ˏ.get(str);
            if (aVar != null) {
                aVar.ˏ();
                this.ˏ.remove(str);
            }
        }
    }

    private void ॱ(String str, List<String> list) {
        if (list == null || list.size() == 0) {
            ˊ(str);
            return;
        }
        List arrayList = new ArrayList();
        for (String file : list) {
            arrayList.add(Uri.fromFile(new File(file)));
        }
        a aVar = (a) this.ˏ.get(str);
        if (aVar != null) {
            aVar.ˊ(arrayList);
            this.ˏ.remove(str);
        }
    }
}
